package siruna.WE.DeviceDependent.AndroidViews;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.MethodNotSupportedException;

import siruna.WE.DeviceDependent.WidgetEngine1;
import siruna.WE.core.model.VisualBlock;
import siruna.WE.core.model.VisualBlocks.ListImpl;
import android.R.color;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.DataSetObserver;
import android.graphics.Color;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ListRenderer extends LinearLayout {

	protected Context context;

	public ListRenderer(final Context context, VisualBlock vb) {
		super(context);
		this.context = context;
		System.out.println("halllooooo: ListRenderer geconstrueert");
		ListImpl l = (ListImpl) vb;
		setOrientation(LinearLayout.VERTICAL);

		
		try {
			for (Object e : l.toList()) {
				HashMap<String, String> m = (HashMap<String, String>) e;
				TextView tv = new TextView(context);

				tv.setFocusable(true);
				tv.setFocusableInTouchMode(true);

				
				
				tv.setText(m.get("title"));
				tv.setOnFocusChangeListener(new OnFocusChangeListener() {

					@Override
					public void onFocusChange(View v, boolean hasFocus) {
						if (hasFocus) {
							v.setBackgroundColor(Color.YELLOW);
						} else {
							v.setBackgroundColor(Color.TRANSPARENT);

						}
					}
				});
				tv.setOnClickListener(new OnClickListener(){

					
					@Override
					public void onClick(View v) {
						Intent i = new Intent(Intent.ACTION_VIEW,
								Uri.parse("http://www.google.com"));
						//url nog juist invullen, bijhouden dus
					context.startActivity(i);
					}
					
					
					
					
				});
				
				
				addView(tv);
			}
		} catch (MethodNotSupportedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

	}
}
